/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2020 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef KDSWIDGET_H
#define KDSWIDGET_H

#include <QWidget>
#include <QButtonGroup>
#include <QEvent>
#include <QKeyEvent>
#include <QApplication>
#include <QGSettings/QGSettings>
#include <KF5/KScreen/kscreen/output.h>
#include <KF5/KScreen/kscreen/edid.h>
#include <KF5/KScreen/kscreen/mode.h>
#include <KF5/KScreen/kscreen/config.h>
#include <KF5/KScreen/kscreen/getconfigoperation.h>
#include <KF5/KScreen/kscreen/setconfigoperation.h>

namespace Ui {
class KDSWidget;
}

class QDBusInterface;

class KDSWidget : public QWidget
{
    Q_OBJECT

public:
    explicit KDSWidget(QWidget *parent = nullptr);
    ~KDSWidget();

    void beginSetupKF5();

    void setupComponent();
    void setupConnect();

    int getCurrentStatus();

    void setCurrentUIStatus(int id);

    QString id() const;

    QDBusInterface * ukcciface;

public:
    void setConfig(const KScreen::ConfigPtr &config);
    KScreen::ConfigPtr currentConfig() const;



private:
    void executeCommand(QString cmd,QString paramter);
    QString findFirstOutput();

    int currentid;
    int selectid;

private:
    Ui::KDSWidget *ui;
    QButtonGroup * btnsGroup;

private:
    KScreen::ConfigPtr mConfig = nullptr;
    KScreen::ConfigPtr mPreConfig = nullptr;

    QGSettings*     m_styleSettings;

    static QString  mConfigsDirName;

    QString         m_qssDefaultOrDark;
    QString         m_qssLight;

public:
    enum DisplaySwitchAction {
        TurnOffExternal= 0,
        Clone = 1,
        ExtendToRight = 2,
//        ExtendToLeft = 3,
        TurnOffEmbedded = 3,
        None = 4,
    };
protected:
    void keyPressEvent(QKeyEvent *event);
    void paintEvent(QPaintEvent *event);
    void showEvent(QShowEvent* event);
protected:
    bool event(QEvent *event)
    {
        if(event->type() == QEvent::ActivationChange)
        {
            if(QApplication::activeWindow() != this)
            {
            closeApp();
            return true;
            }

        }
        return QWidget::event(event);

    }

public Q_SLOTS:
    void msgReceiveAnotherOne(const QString &msg);
    void geometryChangedHandle();

private Q_SLOTS:
    void nextSelectedOption();
    void lastSelectedOption();
    void confirmCurrentOption();
    void closeApp();

Q_SIGNALS:
    void tellBtnClicked(int id);

};

#endif // KDSWIDGET_H
